package com.management.controller;

import com.management.po.Materials;
import com.management.service.MaterialsService;
import com.management.vo.MaterialsVO;
import com.management.vo.PurchaseFormVO;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


/**
 * @author XS
 * 物品库存控制器
 * @version 1.0
 */
@Controller
@RequestMapping("/materials")
public class MaterialsConteoller {
    Logger logger = Logger.getLogger(MaterialsConteoller.class);
    @Autowired
    MaterialsService materialsService;
    //查询采购信息
    @RequestMapping("materialslist")
    public String Materials(int companyId,Model model){
        logger.info("进入查询物品库存控住器");
        List<MaterialsVO> list = materialsService.findByCompanyId(companyId);
        System.out.println(list);
        model.addAttribute("list",list);
        return "materialslist";
    }
    //进入修改采购信息
    @RequestMapping("/tomaterials")
    public String toMaterials(int materialsId ,Model model){
        Logger logger = Logger.getLogger("进入修改物品库存控制器");
        MaterialsVO materials = materialsService.findByMaterialsId(materialsId);
        logger.info(materials);
        model.addAttribute("materials",materials);
        return "updatematerials";
    }
    //修改采购信息
    @RequestMapping("/updatematerials")
    public String UpdateMaterials(Materials materials){
        logger.info("进入物品库存信息控制器");
        boolean flag= materialsService.update(materials);
        logger.info(flag);
        return "redirect:http://localhost:8080/management/materials/materialslist.action?companyId=1";
    }
}
